<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>管理分区</title>
		<!-- 导入jquery核心类库 -->
		<script type="text/javascript" src="../../js/jquery-1.8.3.js"></script>
		<!--导入文件上传需要的js-->
		<script type="text/javascript" src="../../js/ocupload/jquery.ocupload-1.1.2.js" ></script>
		<!-- 导入easyui类库 -->
		<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../js/easyui/ext/portal.css">
		<link rel="stylesheet" type="text/css" href="../../css/default.css">
		<script type="text/javascript" src="../../js/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../js/easyui/ext/jquery.portal.js"></script>
		<script type="text/javascript" src="../../js/easyui/ext/jquery.cookie.js"></script>
		<script src="../../js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
		<script type="text/javascript">
		 $.fn.serializeJson=function(){  
		            var serializeObj={};  
		            var array=this.serializeArray();  
		            var str=this.serialize();  
		            $(array).each(function(){  
		                if(serializeObj[this.name]){  
		                    if($.isArray(serializeObj[this.name])){  
		                        serializeObj[this.name].push(this.value);  
		                    }else{  
		                        serializeObj[this.name]=[serializeObj[this.name],this.value];  
		                    }  
		                }else{  
		                    serializeObj[this.name]=this.value;   
		                }  
		            });  
		            return serializeObj;  
		        }; 
			function doAdd(){
				$("#subAreaForm").form('clear');
				$('#addWindow').window("open");
			}
			
			function doEdit(){
				//选中一行
				var rows=$("#grid").datagrid('getSelections');
				if (rows.length==1) {
					//清空窗口
					var row=rows[0];
					$("#subAreaForm").form('clear');
					$("#subAreaForm").form('load',row);
					
					//设置区域
					$("#areaId").combobox('setValue',row.area.id);
					$("#fixedAreaId").combobox('setValue',row.fixedArea.id);
					
					$("#addWindow").window('open');
				} else{
					$.messager.alert("提示","修改只能选择一行","warning");
				}
			}
			
			function doDelete(){
				//选中一行
				var rows=$("#grid").datagrid('getSelections');
				if (rows.length<1) {
					$.messager.alert("提示","选择大于一行的数据","warning");
				} else{
					var array=new Array();
					for (var i=0;i<rows.length;i++) {
						array.push(rows[i].id);
					}
					var ids=array.join(",");
					window.location.href="../../subArea_deltag.action?ids="+ids;
				}
			}
			function doBack(){
				//选中一行
				var rows=$("#grid").datagrid('getSelections');
				if (rows.length<1) {
					$.messager.alert("提示","选择大于一行的数据","warning");
				} else{
					var array=new Array();
					for (var i=0;i<rows.length;i++) {
						array.push(rows[i].id);
					}
					var ids=array.join(",");
					window.location.href="../../subArea_backtag.action?ids="+ids;
				}
			}
			
			function doSearch(){
				//先清空
				$("#searchForm").form('clear');
				$('#searchWindow').window("open");
			}
			
			function doExport(){
				alert("导出");
			}
			
			
			
			//工具栏
			var toolbar = [ {
				id : 'button-search',	
				text : '查询',
				iconCls : 'icon-search',
				handler : doSearch
			}, {
				id : 'button-add',
				text : '增加',
				iconCls : 'icon-add',
				handler : doAdd
			}, {
				id : 'button-edit',	
				text : '修改',
				iconCls : 'icon-edit',
				handler : doEdit
			},{
				id : 'button-delete',
				text : '作废',
				iconCls : 'icon-cancel',
				handler : doDelete
			},{
				id : 'button-back',
				text : '还原',
				iconCls : 'icon-back',
				handler : doBack
			},{
				id : 'button-import',
				text : '导入',
				iconCls : 'icon-redo',
			},{
				id : 'button-export',
				text : '导出',
				iconCls : 'icon-undo',
				handler : doExport
			}];
			// 定义列
			var columns = [ [ {
				field : 'id',
				checkbox : true,
			}, {
				field : 'showid',
				title : '分拣编号',
				width : 120,
				align : 'center',
				formatter : function(data,row ,index){
					return row.id;
				}
			},{
				field : 'area.province',
				title : '省',
				width : 120,
				align : 'center',
				formatter : function(data,row ,index){
					if(row.area != null ){
						return row.area.province;
					}
					return "" ;
				}
			}, {
				field : 'area.city',
				title : '市',
				width : 120,
				align : 'center',
				formatter : function(data,row ,index){
					if(row.area != null ){
						return row.area.city;
					}
					return "" ;
				}
			}, {
				field : 'area.district',
				title : '区',
				width : 120,
				align : 'center',
				formatter : function(data,row ,index){
					if(row.area != null ){
						return row.area.district;
					}
					return "" ;
				}
			}, {
				field : 'keyWords',
				title : '关键字',
				width : 120,
				align : 'center'
			}, {
				field : 'startNum',
				title : '起始号',
				width : 100,
				align : 'center'
			}, {
				field : 'endNum',
				title : '终止号',
				width : 100,
				align : 'center'
			} , {
				field : 'single',
				title : '单双号',
				width : 100,
				align : 'center',
				formatter:function(data,row ,index){
					if(data==0){
						return "单双号"
					}else if(data==1){
						return "单号"
					}else{
						return "双号"
					}
					
				}
				
			} , {
				field : 'assistKeyWords',
				title : '辅助关键字',
				width : 100,
				align : 'center'
			}, {
				field : 'deltag',
				title : '是否作废',
				width : 120,
				align : 'center',
				formatter : function(data,row, index){
					if(data==null){
						return "正常使用"
					}else if(data==1){
						return "已作废";
					}
				}
			} ] ];
			
			$(function(){
				// 先将body隐藏，再显示，不会出现页面刷新效果
				$("body").css({visibility:"visible"});
				
				// 分区管理数据表格
				$('#grid').datagrid( {
					iconCls : 'icon-forward',
					fit : true,
					border : true,
					rownumbers : true,
					striped : true,
					pageList: [30,50,100],
					pagination : true,
					toolbar : toolbar,
					url : "../../subArea_findPageQuery.action",
					idField : 'id',
					columns : columns,
					onDblClickRow : doDblClickRow
				});
				
				// 添加、修改分区
				$('#addWindow').window({
			        title: '添加修改分区',
			        width: 600,
			        modal: true,
			        shadow: true,
			        closed: true,
			        height: 400,
			        resizable:false
			    });
				
				// 查询分区
				$('#searchWindow').window({
			        title: '查询分区',
			        width: 400,
			        modal: true,
			        shadow: true,
			        closed: true,
			        height: 400,
			        resizable:false
			    });
				$("#btn").click(function(){
					alert("执行查询...");
				});
				
				$("#button-import").upload({
					action:"../../subArea_batchImport.action",
					//过滤上传文件的格式
					onSelect:function(){
					     //关闭自动提交
				         this.autoSubmit=false;
				         //获得文件的名字
				         var filename=this.filename();
				         //编写正则表达式
				         var regex=/^.*\.(xls|xlsx)$/;
				         //判断是否满足正则，
				         if(regex.test(filename)){
				         	//满足就提交
				         	this.submit();
				         }else{
				         	$.messager.alert("上传提示","上传的文件只能是xls，xlsx格式","warning");
				         }
					},
					//数据返回
					onComplete:function(response){
						//相应回数据，刷新（重新加载）
			    		$("#grid").datagrid('reload');
					}
					
				});
				
				$("#searchBtn").click(function(){
					var pamars=$("#searchForm").serializeJson();
					$("#grid").datagrid('load',pamars);
					$("#searchWindow").window('close');
				});
				
				$("#save").click(function(){
					if($("#subAreaForm").form('validate')){
						$("#subAreaForm").submit();
					}else{
						$.messager.alert("提示","有不符合规矩的数据","warning");
					}
				});
				
			});
		
			function doDblClickRow(){
				alert("双击表格数据...");
			}
		</script>
	</head>

	<body class="easyui-layout" style="visibility:hidden;">
		<div region="center" border="false">
			<table id="grid"></table>
		</div>
		<!-- 添加 修改分区 -->
		<div class="easyui-window" title="分区添加修改" id="addWindow" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:200px">
			<div style="height:31px;overflow:hidden;" split="false" border="false">
				<div class="datagrid-toolbar">
					<a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true">保存</a>
				</div>
			</div>

			<div style="overflow:auto;padding:5px;" border="false">
				<form id="subAreaForm" action="../../subArea_save.action" method="post">
					<table class="table-edit" width="80%" align="center">
						<tr class="title">
							<td colspan="2">分区信息</td>
						</tr>
						<tr>
							<td>分拣编码</td>
							<td>
								<input type="text" name="id" class="easyui-validatebox" required="true" />
							</td>
						</tr>
						<tr>
							<td>选择区域</td>
							<td>
								<input id="areaId" class="easyui-combobox" name="area.id" data-options="required:'true',valueField:'id',textField:'info',url:'../../area_findAll.action'" />
							</td>
						</tr>
						<tr>
							<td>选择定区</td>
							<td>
								<input id="fixedAreaId" class="easyui-combobox" name="fixedArea.id" data-options="required:'true',valueField:'id',textField:'fixedAreaName',url:'../../fixedArea_findAll.action'" />
							</td>
						</tr>
						<tr>
							<td>关键字</td>
							<td>
								<input type="text" name="keyWords" class="easyui-validatebox" required="true" />
							</td>
						</tr>
						<tr>
							<td>起始号</td>
							<td>
								<input type="text" name="startNum" class="easyui-validatebox" required="true" />
							</td>
						</tr>
						<tr>
							<td>终止号</td>
							<td>
								<input type="text" name="endNum" class="easyui-validatebox" required="true" />
							</td>
						</tr>
						<tr>
							<td>单双号</td>
							<td>
								<select id="selectNum" class="easyui-combobox" name="single" style="width:150px;">
									<option value="0">单双号</option>
									<option value="1">单号</option>
									<option value="2">双号</option>
								</select>
							</td>
						</tr>
						<tr>
							<td>辅助关键字</td>
							<td>
								<input type="text" name="assistKeyWords" class="easyui-validatebox" required="true" style="width:250px;" />
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
		<!-- 查询分区 -->
		<div class="easyui-window" title="查询分区窗口" id="searchWindow" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:200px">
			<div style="overflow:auto;padding:5px;" border="false">
				<form id="searchForm">
					<table class="table-edit" width="80%" align="center">
						<tr class="title">
							<td colspan="2">查询条件</td>
						</tr>
						<tr>
							<td>省</td>
							<td>
								<input type="text" name="area.province" class="easyui-validatebox" />
							</td>
						</tr>
						<tr>
							<td>市</td>
							<td>
								<input type="text" name="area.city" class="easyui-validatebox" />
							</td>
						</tr>
						<tr>
							<td>区（县）</td>
							<td>
								<input type="text" name="area.district" class="easyui-validatebox" />
							</td>
						</tr>
						<tr>
							<td>定区编码</td>
							<td>
								<input type="text" name="fixedArea.id" class="easyui-validatebox"  />
							</td>
						</tr>
						<tr>
							<td>关键字</td>
							<td>
								<input type="text" name="keyWords" class="easyui-validatebox"  />
							</td>
						</tr>
						<tr>
							<td colspan="2"><a id="searchBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a> </td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</body>

</html>